#include "InputConfigWidget.h"
#include "UrlShortener.h"
#include <QSettings>

namespace TWCore
{
	InputConfigWidget::InputConfigWidget()
	{
		ui.setupUi(this);
		QSettings setting(qApp->applicationDirPath() + "/setting.ini",QSettings::IniFormat);
		setting.beginGroup("Input");
		bool useEnter = setting.value("UseEnterToSend",true).toBool();
		useEnter ? ui.enterRB->setChecked(true):ui.ctrlEnterRB->setChecked(true);

		QString service = setting.value("ShortUrlService","").toString();
		QStringList services = UrlShortener::getServices();
		int index = services.indexOf(service);
		if(index == -1)
			index = 0;
		ui.shortUrlCB->addItems(services);
		ui.shortUrlCB->setCurrentIndex(index);

		ui.autoCloseInputterCB->setChecked(setting.value("AutoCloseInputter",false).toBool());
		ui.autoCloseMailCB->setChecked(setting.value("AutoCloseMailDialog",false).toBool());
	}

	InputConfigWidget::~InputConfigWidget(){}

	void InputConfigWidget::saveSetting()
	{
		QSettings setting(qApp->applicationDirPath() + "/setting.ini",QSettings::IniFormat);
		setting.beginGroup("Input");
		setting.setValue("UseEnterToSend",ui.enterRB->isChecked());
		setting.setValue("ShortUrlService",ui.shortUrlCB->currentText());
		setting.setValue("AutoCloseInputter",ui.autoCloseInputterCB->isChecked());
		setting.setValue("AutoCloseMailDialog",ui.autoCloseMailCB->isChecked());
	}
}
